package com.junwei.smsdemo.controller;

import com.junwei.smsdemo.dto.SendSmsDto;
import com.junwei.smsdemo.dto.VerifyCodeDto;
import com.junwei.smsdemo.service.SmsService;
import com.junwei.smsdemo.util.RedisUtil;
import com.junwei.smsdemo.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @auther 王军伟
 * @create 2019-10-13 11:40
 * @desc
 */
@RestController
@RequestMapping("sms")
public class SmsController {

    @Autowired
    private SmsService smsService;

    @Resource
    private RedisUtil redisUtil;

    @PostMapping("send")
    public Result send(@RequestBody SendSmsDto sendSmsDto) {
        smsService.sendSmsCode(sendSmsDto);
        return Result.success("");
    }

    @PostMapping("verify")
    public Result verify(@RequestBody VerifyCodeDto verifyCodeDto) {
        smsService.verifyCode(verifyCodeDto);
        return Result.success("");
    }

    @PostMapping("testIsSave")
    public String testRedis(@RequestParam String key,@RequestParam String value,@RequestParam Long expire){
        redisUtil.setCacheObject(key,value,expire);
        return "1";
    }

    @PostMapping("getExpireTime")
    public Long getTime(@RequestParam String key){
        //过期时间，毫秒
        long time = redisUtil.getTime(key);
        return time;
    }
}
